package com.myway.service.ibe.controller;

import com.alibaba.fastjson.JSON;
import com.myway.dto.ibe_param.FlightParam;
import com.myway.dto.ibe_param.TicketPrice;
import com.myway.service.ibe.command.FarRuleCommand;
import com.myway.service.ibe.command.FareCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

/**
 * Created by yufei on 2018/6/4.
 */
@Controller
@RequestMapping("/price")
public class FareController {

    @Autowired
    private FareCommand fareCommand;

    @Autowired
    private FarRuleCommand farRuleCommand;


    @RequestMapping("/fare")
    @ResponseBody
    public String searchFare(@RequestBody String json){

        List<FlightParam>  params = JSON.parseArray(json,FlightParam.class);
        List<TicketPrice> ticketPrices =fareCommand.execute(params);

        //TODO:调用接口查询票价
        return JSON.toJSONString(ticketPrices);
    }

    @RequestMapping("/rule")
    @ResponseBody
    public void searchRule() throws ParseException {
        farRuleCommand.execute();
    }
}
